<template>
  <div class="box2">
    <!-- 按钮 -->
    <div class="btn">
      <div class="btn3" :model="searchFromData">
        <el-button @click="doSearch" type="primary" icon="el-icon-search"
          >查询</el-button
        >
      </div>
      <div class="btn4">
        <el-input
          placeholder="请输入关键词搜索"
          prefix-icon="el-icon-search"
          v-model="input21"
        >
        </el-input>
      </div>
    </div>
    <!-- 列表 -->
    <div class="list2">
      <el-table
        :data="
          tableData2.slice((currentPage - 1) * pageSize, currentPage * pageSize)
        "
        border
        stripe
        style="width: 100%"
      >
        <el-table-column
          prop="number"
          label="序号"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="name"
          label="姓名"
          align="center"
        ></el-table-column>
        <el-table-column prop="radio" label="单选题成绩" align="center">
        </el-table-column>
        <el-table-column prop="check" label="多选题成绩" align="center">
        </el-table-column>
        <el-table-column prop="judge" label="判断题成绩" align="center">
        </el-table-column>
        <el-table-column prop="total" sortable label="总成绩" align="center">
        </el-table-column>
        <el-table-column prop="level" label="等级" align="center">
          <template slot-scope="scope">
            <div class="spa" :style="classObje(scope.row.level)">
              <span>
                {{ scope.row.level }}
              </span>
            </div>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" align="center">
          <template>
            <el-button @click="goShijuan" size="small" type="success"
              >详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页器 -->
    <div class="footer">
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          @prev-click="upChange"
          @next-click="nextChange"
          :current-page="currentPage"
          :page-sizes="[5, 10, 20, 30]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData2.length"
          background
          strip
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  methods: {
    //查询功能
    searchFromData() {},
    // 详情按钮点击跳转试卷界面
    goShijuan() {
      this.$router.push("/Shijuan");
    },
    //分页功能实现
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.currentPage = 1;
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
    },
    upChange(val) {
      console.log(val);
      this.currentPage -= 1;
    },
    nextChange(val) {
      console.log(val);
      this.currentPage += 1;
    },
  },

  computed: {
    //通过传来的值判断颜色
    classObje(level) {
      return (level) => {
        if (level == "优") {
          return {
            color: "green",
            border: "1px solid green",
          };
        } else if (level == "良") {
          return {
            color: "yellow",
            border: "1px solid yellow",
          };
        } else if (level == "中") {
          return {
            color: "blue",
            border: "1px solid blue",
          };
        } else if (level == "差") {
          return {
            color: "red",
            border: "1px solid red",
          };
        }
      };
    },
  },
  data() {
    return {
      //分页器
      pageSize: 5,
      currentPage: 1,
      total: 100,
      // searchFromData: "",
      input21: "",
      tableData2: [
        {
          number: "1",
          name: "张三",
          radio: "30",
          check: "30",
          judge: "20",
          total: "70",
          level: "中",
        },
        {
          number: "2",
          name: "张三",
          radio: "30",
          check: "30",
          judge: "20",
          total: "90",
          level: "优",
        },
        {
          number: "3",
          name: "张三",
          radio: "30",
          check: "30",
          judge: "20",
          total: "60",
          level: "差",
        },
        {
          number: "4",
          name: "张三",
          radio: "30",
          check: "30",
          judge: "20",
          total: "30",
          level: "差",
        },
        {
          number: "5",
          name: "张三",
          radio: "30",
          check: "30",
          judge: "20",
          total: "40",
          level: "差",
        },
        {
          number: "6",
          name: "张三",
          radio: "30",
          check: "30",
          judge: "20",
          total: "80",
          level: "良",
        },
        {
          number: "7",
          name: "张三",
          radio: "30",
          check: "30",
          judge: "20",
          total: "80",
          level: "良",
        },
        {
          number: "8",
          name: "张三",
          radio: "30",
          check: "30",
          judge: "20",
          total: "80",
          level: "中",
        },
        {
          number: "9",
          name: "张三",
          radio: "30",
          check: "30",
          judge: "20",
          total: "80",
          level: "中",
        },
        {
          number: "10",
          name: "张三",
          radio: "30",
          check: "30",
          judge: "20",
          total: "80",
          level: "中",
        },
      ],
    };
  },
};
</script>

<style scoped>
.btn {
  height: 40px;
  width: 100%;
  margin-bottom: 16px;
}
.box2 {
  width: 90%;
  margin: 0 auto;
  margin-top: 20px;
  height: 100%;
}
.list2 {
  height: 750px;
  overflow-y: auto;
}
.btn3 {
  float: right;
  height: 33px;
  margin-left: 5px;
  margin-right: 10px;
  width: 80px;
  background-color: #409eff;
  border: 1px solid white;
  border-radius: 10px;
  color: azure;
  font-size: 16px;
  font-family: "黑体";
  margin-bottom: 5px;
}
.btn4 {
  float: right;
  height: 25px;
  width: 200px;
}
span {
  font-size: 17px;
}
.spa {
  width: 25px;
  height: 25px;
  border-radius: 50%;
  border: 1px solid black;
  margin: 0 auto;
}
.footer {
  float: right;
}
</style>